function [t2m_yrs_single, debt_overhang_single, dmarray, doarray, Nvec, rhovec] = debt_overhang_single_vs_diverse_given_leverage(Rate, isdiffrho, isuneqasset, isuneqvol)

%%%% these setting are used in the example in the paper
Settle = datetime(2009,1,1);
Maturity  = datetime(2010,6,1); 
t2m_yrs_single = years(Maturity - Settle);

Compounding = -1;
RateSpec = intenvset('ValuationDate', Settle, 'StartDates', ...
    Settle, 'EndDates', Maturity, 'Rates', Rate, 'Compounding', Compounding);

single_asset = 100;
sigma = 0.4;

debt2asset = 0.6;
Strike = debt2asset*single_asset;

%%%% diversified firm value and debt overhang
OptSpec = {'call'};
struc_input_diverse.RateSpec = RateSpec;
struc_input_diverse.OptSpec = OptSpec;
struc_input_diverse.Strike = Strike;
struc_input_diverse.Settle = Settle;
struc_input_diverse.Maturity = Maturity;

%%%% single-segment firm value and debt overhang

StockSpec_single = stockspec(sigma, single_asset);
Strike_single= single_asset*debt2asset;

struc_input_single.RateSpec = RateSpec;
struc_input_single.StockSpec = StockSpec_single;
struc_input_single.OptSpec = OptSpec;
struc_input_single.Strike = Strike_single;
struc_input_single.Settle = Settle;
struc_input_single.Maturity = Maturity;
[equity_single_mv, equity_single_Delta] = optstocksensbybls(RateSpec, StockSpec_single, Settle, Maturity, OptSpec, Strike_single, 'OutSpec', {'Price', 'Delta'});
debt_overhang_single = 1 - equity_single_Delta;


Nvec = (2:10)';
rhovec = [0; 0.1; 0.3];
dmarray = nan(length(Nvec), length(rhovec));
doarray = nan(length(Nvec), length(rhovec));

rhoNarray = [kron(rhovec, ones(length(Nvec), 1)), repmat(Nvec, length(rhovec), 1)];

parfor i = 1:size(rhoNarray, 1)
    struc_input_diverse_i = struc_input_diverse;
    rho = rhoNarray(i, 1);
    N = rhoNarray(i, 2);
    if isuneqasset
        weightvec = (1:N)'/sum(1:N);
        diverse_assets = single_asset*weightvec;
    else
        weightvec = repmat(1/N, N, 1);
        diverse_assets = repmat(single_asset/N, N, 1);
    end
    Corr = eye(N);
    if isuneqvol
        Volatility = linspace(sigma-0.1, sigma + 0.1, N)';
        weightvec_vol = Volatility/sum(Volatility);
    else
        weightvec_vol = repmat(1/N, N, 1);
        Volatility = repmat(sigma, N, 1);
    end
    Quantity = ones(N, 1);
    if isdiffrho && N > 2
        zerom = zeros(N);
        testmatrix = ones(N);
        uppartidvec = find(tril(testmatrix) == 0);
        rhotril = linspace(-0.2, 0.2, length(uppartidvec))' + rho;
        zerom(uppartidvec) = rhotril;
        Corr = zerom + zerom' + Corr;
    else
        Corr(Corr == 0) = rho;
    end
    AssetPrice =  diverse_assets;
    BasketStockSpec = basketstockspec(Volatility, AssetPrice, Quantity, Corr);
    struc_input_diverse_i.StockSpec = BasketStockSpec;
    struc_input_diverse_i.weightvec = weightvec;
    struc_input_diverse_i.weightvec_vol = weightvec_vol;
    struc_input_diverse_i.investweightvec = weightvec;
    [dmarray(i), ~, doarray(i)] = debtmat_given_equity(equity_single_mv, 'diverse', struc_input_diverse_i, false);
end

end